package com.example.kafka.task;

import com.example.kafka.constant.KafkaConstant;
import com.example.kafka.service.KafkaProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.stream.IntStream;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/4/12 22:10
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
@Slf4j
@Component
@EnableScheduling
public class MessageProductor {

    @Autowired
    KafkaProducer kafkaProducer;

    //@Scheduled(cron="0/10 * * * * ? ")
    public void messageProducter() {
        log.info("准备提供生产数据");
        IntStream.range(0,KafkaConstant.ONCE_SEND_SIZE).forEach(v->{
            kafkaProducer.send(KafkaConstant.generatorUuid());
        });
    }

}
